package com.bitcat.firstapp.demo.component

import android.os.Bundle
import android.view.View
import android.widget.Toast
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.bitcat.firstapp.R

class ButtonDemoActivity : AppCompatActivity(),View.OnClickListener {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_button_demo)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }

        val button2 = findViewById<View>(R.id.button2)
        button2.setOnClickListener {
            Toast.makeText(this, "click2", Toast.LENGTH_SHORT).show()
        }

        val button3 = findViewById<View>(R.id.button3)
        val button4 = findViewById<View>(R.id.button4)

        button3.setOnClickListener(this)
        button4.setOnClickListener(this)
    }

    fun click1(view: View) {
        Toast.makeText(this, "click1", Toast.LENGTH_SHORT).show()
    }

    override fun onClick(v: View) {

        when(v.id){
            R.id.button3 ->{
                Toast.makeText(this, "click3", Toast.LENGTH_SHORT).show()
            }
            R.id.button4 ->{
                Toast.makeText(this, "click4", Toast.LENGTH_SHORT).show()
            }
        }
    }
}